package com.foruo.demo.spring.redis.config;

import com.foruo.demo.spring.redis.entity.DemoEntity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@ComponentScan
public class RedisConfig {

    @Bean
    public RedisConnectionFactory getRedisConnectionFactory(){
        return new JedisConnectionFactory();
    }


    @Bean
    public RedisTemplate<String, DemoEntity> redisTemplate(RedisConnectionFactory cf){
        RedisTemplate<String, DemoEntity> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(cf);
        return redisTemplate;
    }

    @Bean
    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory cf){
        return new StringRedisTemplate(cf);
    }

}
